'use strict';

var _gulp = require('gulp');

var _gulp2 = _interopRequireDefault(_gulp);

var _gulpLoadPlugins = require('gulp-load-plugins');

var _gulpLoadPlugins2 = _interopRequireDefault(_gulpLoadPlugins);

var _del = require('del');

var _del2 = _interopRequireDefault(_del);

var _webpack = require('webpack');

var _webpack2 = _interopRequireDefault(_webpack);

var _webpackProduction = require('./webpack.production.config');

var _webpackProduction2 = _interopRequireDefault(_webpackProduction);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var $ = (0, _gulpLoadPlugins2.default)(); // generated on 2015-10-12 using generator-gulp-webapp 1.0.3


var config = {
    srcDir: 'src/', //源文件目录
    distDir: 'dist/', //编译后产物目录
    tmpDir: '.tmp/', //临时目录
    testDir: 'test/', //测试目录
    prefix: '/',
    staticServe: {
        port: 9000
    }
};

_gulp2.default.task('html', function () {
    var assets = $.useref.assets({
        searchPath: [config.tmpDir],
        transformPath: function transformPath(filePath) {
            return filePath;
        }
    });

    return _gulp2.default.src(['views/*.html']).pipe(assets).pipe($.rev()).pipe(_gulp2.default.dest(config.distDir)).pipe(assets.restore()).pipe($.useref()).pipe($.revReplace({
        prefix: config.prefix
    })).pipe($.filter('*.html')).pipe(_gulp2.default.dest('views'));
});

_gulp2.default.task('webpack', function (callback) {
    (0, _webpack2.default)(_webpackProduction2.default, function (err, status) {
        if (err) {
            console.log('webpack ERR: ' + err);
        }
        callback && callback();
    });
});

_gulp2.default.task('copy:html', function () {
    return _gulp2.default.src(config.distDir + '/src/views/*.html').pipe(_gulp2.default.dest('views'));
});

_gulp2.default.task('clean:pre', _del2.default.bind(null, [config.tmpDir, config.distDir, 'views']));

_gulp2.default.task('build', [/*'clean:pre',*/'webpack'], function () {
    _gulp2.default.start('copy:html');
});
